package cn.gorit.user.controller;

import cn.gorit.common.lang.Result;
import cn.gorit.dto.user.SubDto;
import cn.gorit.dto.user.SubListDto;
import cn.gorit.entity.user.User;
import cn.gorit.user.service.SubscribeService;
import cn.gorit.utils.Page;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @version v1.0
 * @Classname SubscribeController
 * @Description 订阅的相关 RestController
 * @Author Gorit
 * @Created by 2021/3/16 0:30
 * @IDLE IntelliJ IDEA
 **/
@RestController
@RequestMapping("/api/v1/front/sub")
public class SubscribeController {

    @Autowired
    private SubscribeService service;

    // 查询关注状态
    @RequestMapping(path =  "/{curId}/{subedId}", method = RequestMethod.GET)
    public Result<Object> getSubedUserStatus(@PathVariable("curId")  String curId, @PathVariable("subedId") String subedId) {
        return service.getSubBySubId(curId + "-" + subedId);
    }

    // 关注接口 （更新关注状态什么的）
    @PostMapping
    public Result<Object> subUser(@RequestBody SubDto dto) {
        return service.sub(dto);
    }

    // 取消订阅（取消关注）
    @DeleteMapping("/{subId}")
    public Result<Object> cancelSub(@PathVariable("subId")  String subId) {
        return service.can_sub(subId);
    }

    // 获取我的关注列表
    @PostMapping("/list/page")
    public Result<Page<SubListDto>> getSubList(@RequestBody Page<SubListDto> page) {
        return service.getSubList(page);
    }

    // 获取我的粉丝列表
    @PostMapping("/fans/list/page")
    public Result<Page<SubListDto>> getFansList(@RequestBody Page<SubListDto> page) {
        return service.getFansList(page);
    }

    // RPC 调用：根据订阅列表，查看关注人的具体信息等
    @GetMapping("/user/detail/{userId}")
    public Result<User> getUserById(@PathVariable("userId") String userId) {
        return service.getUserDetail(userId);
    }

}
